//
//  MassageProgram.m
//  massage
//
//  Created by 李志权 on 2017/1/4.
//  Copyright © 2017年 李志权. All rights reserved.
//

#import "MassageProgram.h"
#import "LeftMassageOperation.h"
@interface MassageProgram ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSDictionary *data;
@end

@implementation MassageProgram

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"按摩程序";
    
    
    self.data = @{@"肩颈部":@[@"",@"",@"",@"",@"",@""],@"背部":@[@"",@"",@"",@"",@"",@""]};
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Width, Highly) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = NO;
    self.tableView.rowHeight = 60;
    [self.view addSubview:self.tableView];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.data && self.data.count) {
        return self.data.count;
    }
    return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.data && self.data.count) {
        NSArray *keys = [self.data allKeys];
        NSArray *array  = self.data[keys[section]];
        return array.count;
    }
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor =MAINBGCOLOR;
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, Width-40, 30)];
    lable.textColor = MAINBLUEGrayDark;
    lable.font = fontSizeNormal;
    NSArray *keys = [self.data allKeys];
    lable.text = keys[section];
    [view addSubview:lable];
    return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"MassageProgramCellID";
    MassageProgramCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[MassageProgramCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    if (self.data && self.data.count>indexPath.section) {
        NSArray *keys = [self.data allKeys];
        NSArray *array = self.data[keys[indexPath.section]];
        
        cell.image.image = [UIImage imageNamed:@"按摩选项_icon1"];
        cell.typeLable.text = @"按压";
        cell.dateLable.text = [NSString stringWithFormat:@"%@",[NSDate date]];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LeftMassageOperation *VC = [[LeftMassageOperation alloc]init];
    
    [self.navigationController pushViewController:VC animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@implementation MassageProgramCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.image = [[SDNetImageView alloc]initWithFrame:CGRectMake(20, 15, 30, 30)];
        [self.image setShearRound:15 masksToBounds:YES borderWidth:0 borderColor:nil];
        self.image.backgroundColor = GreenColor;
        [self.contentView addSubview:self.image];
        
        self.typeLable = [[UILabel alloc]initWithFrame:CGRectMake(self.image.XWidth+20, 0, 200, 60)];
        self.typeLable.font = [UIFont systemFontOfSize:15];
        self.typeLable.textColor = MAINBLUEGrayDark;
        [self.contentView addSubview:self.typeLable];
        
        self.dateLable = [[UILabel alloc]initWithFrame:CGRectMake(Width-85, 0, 65, 60)];
        self.dateLable.font = fontSizeMinMin;
        self.dateLable.textColor = GrayLight;
        [self.contentView addSubview:self.dateLable];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20, 59, Width-40, 1)];
        line.backgroundColor = GrayTooLight;
        [self.contentView addSubview:line];
    }
    return self;
}

@end

